package com.example.shipback.controller;

import com.example.shipback.BO.GetInfoResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.IOException;

@RequestMapping("/client/ship")
@RestController
@CrossOrigin
@Slf4j
public class ClientController {

    private static final Logger logger = LoggerFactory.getLogger(ClientController.class);

    @GetMapping("/getInfo")
    public GetInfoResponse getInfo() {
        String property = System.getProperty("java.version");
        System.out.println(property);

        String desktopPath = System.getProperty("user.home") + File.separator + "Desktop" + File.separator + "ship.json";

        ObjectMapper objectMapper = new ObjectMapper();

        try {
            return objectMapper.readValue(new File(desktopPath), GetInfoResponse.class);
        } catch (IOException e) {
            logger.info("error message", e);
            return null;
        }

    }

}
